//
//  YHMachineManagementPullDownViewController.m
//  YHApp
//
//  Created by -- on 2021/7/20.
//

#import "HAMachinePullDownVC.h"
#import "HAMachinePullDownAgentPopView.h"
#import "HAHoemAgentListModel.h"
#import "HAMachinePullDownMachinesPopView.h"
#import "HAAllMachineListMo.h"
#import "HASMSendVC.h"
#import "HATermModel.h"

@interface HAMachinePullDownVC ()<UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate>


/***/
@property (nonatomic, strong) HACanalItemMo *selProductModel;
/***/
@property (nonatomic, assign) NSInteger xbType;
/***/
@property (nonatomic, strong) UITextField *minTextField;
/***/
@property (nonatomic, strong) UITextField *maxTextField;
/***/
@property (nonatomic, strong) UIButton *minScanSodeBtn;
/***/
@property (nonatomic, strong) UIButton *maxScanSodeBtn;
/***/
@property (nonatomic, strong) NSMutableArray *selMachineArr;
/***/
@property (nonatomic, strong) NSString *start_sn;
/***/
@property (nonatomic, strong) NSString *end_sn;
/***/
@property (nonatomic, strong) UITextField *prexTextField;


@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic ,strong) NSMutableArray *dataArray;
/***/
@property (nonatomic, strong) HAHoemAgentListModel *selAgentModel;
/***/
@property (nonatomic, strong) NSMutableArray *termList;
/***/
@property (nonatomic, assign) NSInteger number;
/***/
@property (nonatomic, assign) NSInteger type1Number;


@end

@implementation HAMachinePullDownVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.baseTLabel.text = @"机具下拔";
    self.xbType = 2;
    self.number = 0;
    [self loadNewData];
    [self initUI];
    [self loadData];
    
    // Do any additional setup after loading the view.
}

- (void)initUI{
    
    UIButton *bBtn = [[UIButton alloc]init];
    [bBtn setTitle:@"划拔" forState:UIControlStateNormal];
    [bBtn setTitleColor:[UIColor colorWithHexString:@"@ffffff"] forState:UIControlStateNormal];
    bBtn.titleLabel.font = [UIFont systemFontOfSize:18];
    bBtn.backgroundColor = [UIColor colorWithHexString:@"#191919"];
    [bBtn addTarget:self action:@selector(bBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:bBtn];
    [bBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(0);
        make.left.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
        make.height.mas_offset(54);
    }];
    
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(app_topH+44);
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.bottom.mas_equalTo(-54);
    }];
}

-(void)loadData {
    
    [self.dataArray removeAllObjects];
    [self.dataArray addObject:@"下拔代理"];
    [self.dataArray addObject:@"可拔发机具"];
    [self.dataArray addObject:@"下拔方式"];
    [self.dataArray addObject:@"起始编码"];
    [self.dataArray addObject:@"结束编码"];
    [self.dataArray addObject:@"拔发数量"];
    
    [self.tableView reloadData];
    
}


-(void)loadNewData {
    SYRequest *request1 = [[SYRequest alloc]init];
    request1.requestUrl = [NSString stringWithFormat:@"v1/term/dialterms"];
    request1.requestMethod = SYRequestMethodPOST;
    [[SYNetworking shareSingle] hgj_asynRequestWithArray:@[request1] responseBlock:^(SYDataModel *dataModel) {
        if (dataModel.request == request1) {
            if (dataModel.err) {
                [MBProgressHUD showError:@"网络错误"];
                return;
            }
            if (dataModel.code == 1) {
                [self.termList removeAllObjects];
                if ([[dataModel.data allKeys]containsObject:@"term"]) {
                    NSArray *arr = [HATermModel mj_objectArrayWithKeyValuesArray:[dataModel.data valueForKey:@"term"]];
                    [self.termList addObjectsFromArray:arr];
                    self.number = self.termList.count;
                    self.type1Number = self.termList.count;
                }
            }else{
                [MBProgressHUD showError:dataModel.msg];
            }
            [self.tableView reloadData];
        }
    }];
    
}


-(void)bBtnClick {
    
    [self.view endEditing:YES];
    
    if (!self.selAgentModel) {
        [MBProgressHUD showError:@"请选择代理"];
        return;
    }
    
    NSString *code = @"";
    int codeCount = 0;
    if (self.xbType == 1) {
        for (int i = 0; i < self.termList.count; i ++) {
            HATermModel *mo = self.termList[i];
            if (mo.isSel) {
                codeCount += 1;
                if ([NSString isEmptyString:code]) {
                    code = [NSString stringWithFormat:@"%@",mo.value];
                }else {
                    code = [NSString stringWithFormat:@"%@,%@",code,mo.value];
                }
            }
        }
        if ([NSString isEmptyString:code]) {
            [MBProgressHUD showError:@"请选择机具"];
            return;
        }
    }
    if (self.xbType == 2) {
        if ([NSString isEmptyString:self.start_sn]) {
            [MBProgressHUD showError:@"请输入起始编码"];
            return;
        }
        if ([NSString isEmptyString:self.end_sn]) {
            [MBProgressHUD showError:@"请输入结束编码"];
            return;
        }
    }
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic setValue:self.selAgentModel.ID?:@"" forKey:@"agent_id"];
    
    if (self.xbType == 1) {
        [dic setValue:[NSString stringWithFormat:@"%d",codeCount] forKey:@"number"];
        [dic setValue:code forKey:@"code"];
        [dic setValue:@"1" forKey:@"is_default"];
    }else if (self.xbType == 2) {
        [dic setValue:[NSString stringWithFormat:@"%ld",(long)self.type1Number] forKey:@"number"];
        [dic setValue:@"0" forKey:@"is_default"];
        [dic setValue:self.start_sn?:@"" forKey:@"start_sn"];
        [dic setValue:self.end_sn?:@"" forKey:@"end_sn"];
    }
    
    [dic setValue:@"" forKey:@"source_id"];
    [dic setValue:@"" forKey:@"policy_id"];
    [dic setValue:@"" forKey:@"prex"];
    
    SYRequest *request = [[SYRequest alloc]init];
    request.requestMethod = SYRequestMethodPOST;
    request.requestUrl = [NSString stringWithFormat:@"sns/dial.html"];
    request.parms = dic;
    [MBProgressHUD showLoading:self.view];
    
    [[SYNetworking shareSingle] hgj_asynRequestWithArray:@[request] responseBlock:^(SYDataModel *dataModel) {
        if (dataModel.request == request) {
            [MBProgressHUD hideHUDForView:self.view];
            if (dataModel.err) {
                [MBProgressHUD showError:@"网络错误"];
                return;
            }
            if (dataModel.code == 1) {
                [MBProgressHUD showSuccess:@"机具拨发成功"];
                [self.navigationController popViewControllerAnimated:YES];
            }else {
                [MBProgressHUD showError:dataModel.msg];
            }
        }
    }];
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 55;
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *title = self.dataArray[indexPath.row];
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"YHMachineManagementPullDownIID"];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"YHMachineManagementPullDownIID"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if ([title isEqualToString:@"下拔代理"]) {
        NSString *content = @"";
        if (self.selAgentModel) {
            content = self.selAgentModel.name;
        }else {
            content = @"请选择代理";
        }
        [self setCellConWith:cell.contentView title:title content:content isLine:YES isRImg:YES];
    }else if ([title isEqualToString:@"可拔发机具"]) {
        NSString *content = @"0";
        if (self.termList.count > 0) {
            content = [NSString stringWithFormat:@"%lu",(unsigned long)self.termList.count];
        }
        [self setCellConWith:cell.contentView title:title content:content isLine:YES isRImg:NO];
    } else if ([title isEqualToString:@"下拔方式"]) {
        [self setCellBaTypeWith:cell.contentView title:title];
    }else if ([title isEqualToString:@"起始编码"]) {
        [self setCellBaSnWith:cell.contentView title:title content:self.start_sn];
    }else if ([title isEqualToString:@"结束编码"]) {
        [self setCellBaSnWith:cell.contentView title:title content:self.end_sn];
    }else if ([title isEqualToString:@"拔发数量"]) {
        [self setCellBaNumWith:cell.contentView title:title];
    }else if ([title isEqualToString:@"选择机具"]) {
        int count = NO;
        for (int i = 0; i < self.termList.count; i ++) {
            HATermModel *mo = self.termList[i];
            if (mo.isSel) {
                count += 1;
            }
        }
        NSString *content = [NSString stringWithFormat:@"已经选机具%d个",count];
        [self setCellConWith:cell.contentView title:title content:content isLine:YES isRImg:YES];
    }else if ([title isEqualToString:@"机具前缀"]) {
        [self setCellPrexWith:cell.contentView];
    }
    
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [self.view endEditing:YES];
    WS(weakSelf)
    NSString *title = self.dataArray[indexPath.row];
    if ([title isEqualToString:@"下拔代理"]) {
        HAMachinePullDownAgentPopView *menu = [[HAMachinePullDownAgentPopView alloc]initWithTitle:title];
        [menu show];
        menu.HAMachinePullDownAgentPopSureBlock = ^(HAHoemAgentListModel * _Nonnull model) {
            weakSelf.selAgentModel = model;
            for (int i = 0; i < weakSelf.termList.count; i ++) {
                HATermModel *mo = weakSelf.termList[i];
                mo.isSel = NO;
            }
            [weakSelf.tableView reloadData];
        };
    }
    
    if ([title isEqualToString:@"选择机具"]) {
        HAMachinePullDownMachinesPopView *menu = [[HAMachinePullDownMachinesPopView alloc]initWithArray:self.termList];
        [menu show];
        menu.HAMachinePullDownMachinesMenuSureBlock = ^{
            [weakSelf.tableView reloadData];
        };
    }
}

-(void)typeBtn1Click {
    [self.view endEditing:YES];
    self.xbType = 1;
    [self.dataArray removeAllObjects];
    [self.dataArray addObject:@"下拔代理"];
    [self.dataArray addObject:@"可拔发机具"];
    [self.dataArray addObject:@"下拔方式"];
    [self.dataArray addObject:@"选择机具"];
    [self.tableView reloadData];
}

-(void)typeBtn2Click {
    [self.view endEditing:YES];
    self.xbType = 2;
    [self.dataArray removeAllObjects];
    [self.dataArray addObject:@"下拔代理"];
    [self.dataArray addObject:@"可拔发机具"];
    [self.dataArray addObject:@"下拔方式"];
    [self.dataArray addObject:@"起始编码"];
    [self.dataArray addObject:@"结束编码"];
    [self.dataArray addObject:@"拔发数量"];
    [self.tableView reloadData];
}

-(void)scanSodeBtnClick:(UIButton *)button {
    [self.view endEditing:YES];
    WS(weakSelf)
    
    if ([HAHelper isCamera]) {
        HASMSendVC *vc = [[HASMSendVC alloc]init];
        [vc retrunBlock:^(NSString * _Nonnull snText) {
            if (button.tag == 1) {
                weakSelf.start_sn = snText;
            }else if (button.tag == 2) {
                weakSelf.end_sn = snText;
            }
            [weakSelf.tableView reloadData];
        }];
        [self.navigationController pushViewController:vc animated:YES];
    }else {
        HATipsPopView *menu = [[HATipsPopView alloc]initWithTitle:@"温馨提示" content:@"请允许访问您的相机" left:@"取消" right:@"去设置"];
        [menu show];
        menu.XZYGTiShiRightBlock = ^{
            [HAHelper GetPhoneSet];
        };
    }
}

-(void)addButtonClick {
    [self.view endEditing:YES];
    self.type1Number += 1;
    [self.tableView reloadData];
}

-(void)minusButtonClick {
    [self.view endEditing:YES];
    self.type1Number -= 1;
    if (self.type1Number < 0) {
        self.type1Number = 0;
    }
    [self.tableView reloadData];
}

-(void)textFieldDidEndEditing:(UITextField *)textField {
    if (textField == self.minTextField) {
        self.start_sn = textField.text;
    }
    if (textField == self.maxTextField) {
        self.end_sn = textField.text;
    }
}

-(void)setCellConWith:(UIView *)contentView title:(NSString *)title content:(NSString *)content isLine:(BOOL)isline isRImg:(BOOL)isRImg {
    for (UIView *view in contentView.subviews) {
        [view removeFromSuperview];
    }
    
    UILabel *titlabel = [UILabel ha_NLabelWithFont:17 textColor:@"#111a34" text:title alignment:0];
    [contentView addSubview:titlabel];
    [titlabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.left.mas_equalTo(20);
        make.width.mas_offset(100);
    }];
    
    if (isRImg) {
        UIImageView *RImgV = [UIImageView ha_createImageView];
        RImgV.image = [UIImage imageNamed:@"ic_cell_more"];
        [contentView addSubview:RImgV];
        [RImgV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_offset(5);
            make.height.mas_offset(10);
            make.centerY.mas_equalTo(0);
            make.right.mas_equalTo(-20);
        }];
    }
    
    UILabel *conLabel = [UILabel ha_NLabelWithFont:15 textColor:@"#858b9c" text:content alignment:2];
    [contentView addSubview:conLabel];
    [conLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.left.mas_equalTo(titlabel.mas_right).offset(15);
        if (isRImg) {
            make.right.mas_equalTo(-10-20-10);
        }else {
            make.right.mas_equalTo(-20);
        }
    }];
    
    if (isline == YES) {
        UIView *lineView = [UIView ha_createView];
        lineView.backgroundColor = [UIColor khaBGColor];
        [contentView addSubview:lineView];
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(20);
            make.right.mas_equalTo(-20);
            make.height.mas_offset(1);
            make.bottom.mas_equalTo(0);
        }];
    }
}

-(void)setCellBaTypeWith:(UIView *)contentView title:(NSString *)title {
    for (UIView *view in contentView.subviews) {
        [view removeFromSuperview];
    }
    
    UILabel *titlabel = [UILabel ha_NLabelWithFont:17 textColor:@"111a34" text:title alignment:0];
    [contentView addSubview:titlabel];
    [titlabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.left.mas_equalTo(20);
        make.width.mas_offset(100);
    }];
    
    FL_Button *btn1 = [[FL_Button alloc]initWithAlignmentStatus:FLAlignmentStatusNormal];
    [btn1 setTitle:@"选择机具" forState:UIControlStateNormal];
    [btn1 setTitleColor:[UIColor colorWithHexString:@"#858b9c"] forState:UIControlStateNormal];
    btn1.titleLabel.font = [UIFont systemFontOfSize:13];
    btn1.fl_padding = 5;
    [btn1 addTarget:self action:@selector(typeBtn1Click) forControlEvents:UIControlEventTouchUpInside];
    [contentView addSubview:btn1];
    [btn1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-20);
        make.centerY.mas_equalTo(0);
        make.height.mas_offset(44);
        make.width.mas_offset(78);
    }];
    
    FL_Button *btn2 = [[FL_Button alloc]initWithAlignmentStatus:FLAlignmentStatusNormal];
    [btn2 setTitle:@"拔号下拔" forState:UIControlStateNormal];
    [btn2 setTitleColor:[UIColor colorWithHexString:@"#858b9c"] forState:UIControlStateNormal];
    btn2.titleLabel.font = [UIFont systemFontOfSize:13];
    btn2.fl_padding = 5;
    [btn2 addTarget:self action:@selector(typeBtn2Click) forControlEvents:UIControlEventTouchUpInside];
    [contentView addSubview:btn2];
    [btn2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(btn1.mas_left).offset(-15);
        make.centerY.mas_equalTo(0);
        make.height.mas_offset(44);
        make.width.mas_offset(78);
    }];
    
    if (self.xbType == 1) {
        [btn1 setImage:[UIImage imageNamed:@"ha_1_sel"] forState:UIControlStateNormal];
        [btn2 setImage:[UIImage imageNamed:@"ha_1_def"] forState:UIControlStateNormal];
    }else if (self.xbType == 2) {
        [btn1 setImage:[UIImage imageNamed:@"ha_1_def"] forState:UIControlStateNormal];
        [btn2 setImage:[UIImage imageNamed:@"ha_1_sel"] forState:UIControlStateNormal];
    }
    
    UIView *lineView = [UIView ha_createView];
    lineView.backgroundColor = [UIColor khaBGColor];
    [contentView addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        make.height.mas_offset(1);
        make.bottom.mas_equalTo(0);
    }];
}

-(void)setCellBaSnWith:(UIView *)contentView title:(NSString *)title content:(NSString *)content {
    for (UIView *view in contentView.subviews) {
        [view removeFromSuperview];
    }
    
    UILabel *titlabel = [UILabel ha_NLabelWithFont:17 textColor:@"111a34" text:title alignment:0];
    [contentView addSubview:titlabel];
    [titlabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.left.mas_equalTo(20);
        make.width.mas_offset(100);
    }];
    
    UIButton *scanSodeBtn = [[UIButton alloc]init];
    [scanSodeBtn setImage:[UIImage imageNamed:@"ha_11"] forState:UIControlStateNormal];
    [scanSodeBtn addTarget:self action:@selector(scanSodeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [contentView addSubview:scanSodeBtn];
    [scanSodeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-20);
        make.centerY.mas_equalTo(0);
        make.width.mas_offset(22);
        make.height.mas_offset(22);
    }];
    
    UITextField *textField = [[UITextField alloc]init];
    textField.delegate = self;
    textField.textColor = [UIColor colorWithHexString:@"#121B32"];
    textField.font = [UIFont systemFontOfSize:16];
    textField.textAlignment = 2;
    [contentView addSubview:textField];
    [textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.right.mas_equalTo(scanSodeBtn.mas_left).offset(-10);
        make.left.mas_equalTo(titlabel.mas_right);
        make.height.mas_offset(32);
    }];
    
    if ([title isEqualToString:@"起始编码"]) {
        scanSodeBtn.tag = 1;
        textField.text = self.start_sn;
        self.minTextField = textField;
        self.minScanSodeBtn = scanSodeBtn;
        textField.placeholder = @"请输入SN起始编号";
    }
    
    if ([title isEqualToString:@"结束编码"]) {
        scanSodeBtn.tag = 2;
        textField.text = self.end_sn;
        self.maxTextField = textField;
        self.maxScanSodeBtn = scanSodeBtn;
        textField.placeholder = @"请输入SN结束编号";
    }
    
    UIView *lineView = [UIView ha_createView];
    lineView.backgroundColor = [UIColor khaBGColor];
    [contentView addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        make.height.mas_offset(1);
        make.bottom.mas_equalTo(0);
    }];
}

-(void)setCellPrexWith:(UIView *)contentView {
    for (UIView *view in contentView.subviews) {
        [view removeFromSuperview];
    }
    
    UILabel *titlabel = [UILabel ha_NLabelWithFont:17 textColor:@"111a34" text:@"机具前缀" alignment:0];
    [contentView addSubview:titlabel];
    [titlabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.left.mas_equalTo(20);
        make.width.mas_offset(100);
    }];
    
    UITextField *textField = [[UITextField alloc]init];
    textField.delegate = self;
    textField.textColor = [UIColor colorWithHexString:@"#121B32"];
    textField.font = [UIFont systemFontOfSize:16];
    textField.textAlignment = 2;
    [contentView addSubview:textField];
    [textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.right.mas_equalTo(-20);
        make.left.mas_equalTo(titlabel.mas_right);
        make.height.mas_offset(32);
    }];
    
    self.prexTextField = textField;
    textField.placeholder = @"如N";
    
    UIView *lineView = [UIView ha_createView];
    lineView.backgroundColor = [UIColor khaBGColor];
    [contentView addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        make.height.mas_offset(1);
        make.bottom.mas_equalTo(0);
    }];
}


-(void)setCellBaNumWith:(UIView *)contentView title:(NSString *)title {
    for (UIView *view in contentView.subviews) {
        [view removeFromSuperview];
    }
    
    UILabel *titlabel = [UILabel ha_NLabelWithFont:17 textColor:@"111a34" text:title alignment:0];
    [contentView addSubview:titlabel];
    [titlabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(0);
        make.left.mas_equalTo(20);
        make.width.mas_offset(100);
    }];
    
    UIButton *addButton = [[UIButton alloc]init];
    [addButton setTitle:@"+" forState:UIControlStateNormal];
    [addButton setTitleColor:[UIColor colorWithHexString:@"#858B9C"] forState:UIControlStateNormal];
    addButton.titleLabel.font = [UIFont systemFontOfSize:16];
    addButton.backgroundColor = [UIColor colorWithHexString:@"#F9FAFB"];
    addButton.layer.cornerRadius = 4;
    addButton.layer.masksToBounds = YES;
    [addButton addTarget:self action:@selector(addButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [contentView addSubview:addButton];
    [addButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-20);
        make.centerY.mas_equalTo(0);
        make.width.mas_offset(28);
        make.height.mas_offset(28);
    }];
    
    UILabel *numLabel = [UILabel ha_NLabelWithFont:14 textColor:@"#858B9C" text:[NSString stringWithFormat:@"%ld",(long)self.type1Number] alignment:1];
    numLabel.backgroundColor = [UIColor colorWithHexString:@"#F9FAFB"];
    numLabel.layer.cornerRadius = 4;
    numLabel.layer.masksToBounds = YES;
    [contentView addSubview:numLabel];
    [numLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(addButton.mas_left).offset(-4);
        make.centerY.mas_equalTo(addButton);
        make.width.mas_offset(80);
        make.height.mas_offset(28);
    }];
    
    UIButton *minusButton = [[UIButton alloc]init];
    [minusButton setTitle:@"-" forState:UIControlStateNormal];
    [minusButton setTitleColor:[UIColor colorWithHexString:@"#858B9C"] forState:UIControlStateNormal];
    minusButton.titleLabel.font = [UIFont systemFontOfSize:16];
    minusButton.backgroundColor = [UIColor colorWithHexString:@"#F9FAFB"];
    minusButton.layer.cornerRadius = 4;
    minusButton.layer.masksToBounds = YES;
    [minusButton addTarget:self action:@selector(minusButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [contentView addSubview:minusButton];
    [minusButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(numLabel.mas_left).offset(-4);
        make.centerY.mas_equalTo(addButton);
        make.width.mas_offset(28);
        make.height.mas_offset(28);
    }];
    
}

- (UITableView *)tableView {
    if (_tableView == nil) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectZero];
        // 去掉滚动条
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.showsHorizontalScrollIndicator = NO;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        // 设置背景颜色
        _tableView.backgroundColor = [UIColor khaBGColor];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [self.view addSubview:_tableView];
    }
    return _tableView;
}

- (NSMutableArray *)dataArray
{
    if (!_dataArray) {
        _dataArray = [NSMutableArray array ];
    }
    return _dataArray;
}

- (NSMutableArray *)selMachineArr
{
    if (!_selMachineArr) {
        _selMachineArr = [NSMutableArray array];
    }
    return _selMachineArr;
}

- (NSMutableArray *)termList
{
    if (!_termList) {
        _termList = [NSMutableArray array];
    }
    return _termList;
}



@end
